#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/11 8:55
    Desc  :
--------------------------------------
"""
from bson import json_util

from application import mongo


class Log(mongo.Document):
    """
    日志表
    """

    path = mongo.StringField()
    method = mongo.StringField()
    remote_addr = mongo.StringField()
    username = mongo.StringField()
    headers = mongo.DictField()
    params = mongo.DictField()
    response = mongo.StringField()
    startTime = mongo.IntField()
    endTime = mongo.IntField()
    castTime = mongo.IntField()

    def to_json(self):
        return {
            '_id': eval(json_util.dumps(self.id)),
            'path': self.path,
            'method': self.method,
            'params': self.params,
            'remote_addr': self.remote_addr,
            'username': self.username,
            'headers': self.headers,
            'response': self.response,
            'startTime': self.startTime,
            'endTime': self.endTime,
            'castTime': self.castTime,
        }
